package com.liyuci.core.namingstrategy;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;

/**
 * 生成数据库表格的名称和字段名称策略
 * @author liyuci
 * @date 2018-01-24 14:00:15
 */

public class MyImprovedNamingStrategy extends SpringPhysicalNamingStrategy {

	/**
	 * 生成数据库表名称的策略（全小写）
	 */
	@Override
	public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment)
	{
		//return super.toPhysicalTableName(name, jdbcEnvironment);
		if (name == null) {
			return null;
		}
		StringBuilder builder = new StringBuilder(name.getText().replace('.', '_'));
		return getIdentifier(builder.toString(), name.isQuoted(), jdbcEnvironment);
	}

	/**
	 * 生成数据库字段名称的策略（Java驼峰式）
	 */
	@Override
	public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment)
	{
		//return super.toPhysicalColumnName(name, jdbcEnvironment);
		if (name == null) {
			return null;
		}
		StringBuilder builder = new StringBuilder(name.getText().replace('.', '_'));
		return getIdentifier(builder.toString(), name.isQuoted(), jdbcEnvironment);
	}
	
	/**
	 * 大小写是否敏感，修改为false，默认是区分大小写的
	 */
	@Override
    protected boolean isCaseInsensitive(JdbcEnvironment jdbcEnvironment) {
        return false;
    }
}
